package com.chukun.disruptor.higher.chain;

import com.lmax.disruptor.dsl.Disruptor;
import java.util.concurrent.CountDownLatch;

public class TradePublisher implements Runnable {

    private Disruptor<Trade> disruptor;
    private CountDownLatch latch;

    private static final int PUBLISH_COUNT=1;

    public TradePublisher(CountDownLatch latch, Disruptor<Trade> disruptor) {
        this.disruptor = disruptor;
        this.latch = latch;
    }

    @Override
    public void run() {
       try {
           for (int i=0;i<PUBLISH_COUNT;i++){
               TradeEventTranslator tradeEventTranslator = new TradeEventTranslator();
               disruptor.publishEvent(tradeEventTranslator);//发布对象
           }
       }finally {
           latch.countDown();
       }


    }
}
